package com.bit.demo3;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 74646
 * Date: 2022-02-08
 * Time: 18:49
 */

class Animal{
    public String name;
    public int age;

    public Animal(String name,int age){
        this.name = name;
        this.age =age;
    }
    public void eat(){
        System.out.println(this.name + "正在吃");
    }
}

class Dog extends Animal {
    public String name = "嘿嘿";
    public Dog(String name,int age){
        super(name,age); //调用父类带有两个参数的构造方法
    }
}
class Bird extends Animal {

    public String wing;
    public Bird(String name,int age){
        super(name,age); //调用父类带有两个参数的构造方法
    }
    public void fly(){
        System.out.println(this.name+"正在飞");
    }
}
public class TestDemo {
    public static void main(String[] args) {

    }

    public static void main4(String[] args) {
        Animal animal = new Bird("小鸟",6);
        //向下转型
        if(animal instanceof Bird) {
            Bird bird = (Bird)animal;  //需要强制类型转换
            bird.fly();
        }
    }

    public static void main3(String[] args) {
      /*  Dog dog = new Dog("小黑",15);
        Animal animal = dog; // 父类引用  引用 子类对象*/
        Animal animal1 = new Animal("大白",20);
        animal1.eat();
        //向上转型
        Animal animal2 = new Dog("小黑",15); // 父类引用  引用 子类对象
        animal2.eat();
    }

    public static void main1(String[] args) {
       // Animal animal = func();
       // System.out.println(animal);
    }

 /*   public static void func(Animal animal){
        System.out.println(animal.name+"是"+animal.age+"岁");
    }*/
    public static void main2(String[] args) {
        Dog dog = new Dog("小黑",15);
        //func(dog);
    }

}
